package cn.yunyichina.scheduler.jobs.service.message.impl;

import cn.yunyichina.scheduler.jobs.common.service.MessageService;
import cn.yunyichina.scheduler.jobs.dao.message.MedicalReserveRegisterMessageDao;
import cn.yunyichina.scheduler.jobs.entity.register.RegisterRecord;
import cn.yunyichina.scheduler.jobs.service.message.MedicalReserveRegisterMessageService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Lullaby on 2016/8/10.
 */
@Service
public class MedicalReserveRegisterMessageImpl implements MedicalReserveRegisterMessageService {

    private static final Logger logger = LoggerFactory.getLogger(MedicalReserveRegisterMessageImpl.class);

    @Resource
    private MedicalReserveRegisterMessageDao medicalReserveRegisterMessageDao;

    @Resource
    private MessageService messageService;

    public void pushMessageForMedicalReserveRegisterRecord() {
        List<RegisterRecord> records = medicalReserveRegisterMessageDao.getMedicalReserveRecordsOfCurrentDay();
        if (CollectionUtils.isNotEmpty(records)) {
            int size = records.size();
            logger.info("查询到[{}]条待消息推送医保挂号订单", size);
            for (int i = 0; i < size; i++) {
                RegisterRecord record = records.get(i);
                messageService.pushMessage(record, MessageService.ACTION_TYPE_MEDICAL_RESERVE_REGISTER_PAY);
            }
        } else {
            logger.info("未查询到当天待推送消息医保预约挂号订单");
        }
    }

}
